package com.hd.core.project.module.controller;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hd.core.framework.web.controller.BaseController;
import com.hd.core.framework.web.domain.AjaxResult;
import com.hd.core.project.module.async.MailAsync;
import com.hd.core.project.module.config.MainModuleProperties;

/**
 * 系统首页-控制器
 * 
 * <br/>
 * @since JDK 1.8
 * @version  V1.0
 * @author RichardTang 
 * @date: 2018年9月7日
 * @package com.hd.core.project.module.controller
 * @copyright:Copyright (c) 2018, 1245811923@qq.com All Rights Reserved.
 */
@Controller
@RequestMapping("/module/main")
public class MainController extends BaseController{

	@Autowired
	private MainModuleProperties properties;
	
	@Autowired
	private MailProperties mailProperties;
	
	@Autowired
	private MailAsync mailAsync;
	
	/**
	 * <p>反馈问题/意见信息</p>
	 * 
	 * @param title 标题
	 * @param content 内容
	 * 
	 */
	@ResponseBody
	@PostMapping("/feedback")
	@RequiresPermissions("module-main:main:feedback")
	public AjaxResult feedback(String title,String content) {
		if(StringUtils.isNotBlank(title) && StringUtils.isNotBlank(content)) {
			SimpleMailMessage message = new SimpleMailMessage();
			message.setFrom(mailProperties.getUsername());
			message.setTo(properties.getReceiveAccount());
			message.setSubject("学工管理系统("+getUser().getUserName()+")-" + title);
			message.setText(content);
			mailAsync.sendMail(message);
			return success();
		}
	
		return error("标题或者内容为空！");
	}
	
}
